package io.awen.modules.sign.controller;

import io.awen.common.utils.PageUtils;
import io.awen.common.utils.R;
import io.awen.modules.sign.entity.SignCarLoadRecordEntity;
import io.awen.modules.sign.qo.SignCarDispatchQo;
import io.awen.modules.sign.qo.SignCarLoadRecordQo;
import io.awen.modules.sign.service.SignCarLoadRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * 车辆超速报警信息记录表
 */
@RestController
@RequestMapping("sign/signCarLoadRecord")
public class SignCarLoadRecordController {
    @Autowired
    private SignCarLoadRecordService signCarLoadRecordService;

    /**
     * 分页查询
     */
    @RequestMapping("/list") //sign/signCarLoadRecord/list
    public R list(@RequestBody SignCarLoadRecordQo qo) {
        PageUtils page = signCarLoadRecordService.queryPage(qo);
        return R.ok().put("page", page);
    }

    @ApiOperation("司机提交动作")
    @PostMapping("/submit")
    public R submit(@RequestBody SignCarLoadRecordEntity qo) {
        return signCarLoadRecordService.submit(qo);
    }

    @PostMapping("/getSink")
    public R getSink(@RequestBody SignCarLoadRecordEntity qo) {
        return R.ok().put("sink", signCarLoadRecordService.getSink(qo));
    }

    @PostMapping("/getContainer")
    public R getContainer(@RequestBody SignCarLoadRecordEntity qo) {
        return R.ok().put("container", signCarLoadRecordService.getContainer(qo));
    }


    /**
     * 台账
     */
    @RequestMapping("/ledger")
    public R ledger(@RequestBody SignCarLoadRecordQo qo) {
        PageUtils page = signCarLoadRecordService.queryLedger(qo);
        return R.ok().put("page", page);
    }

    @RequestMapping("/queryLedgerDriver")
    public R queryLedgerDriver(@RequestBody SignCarLoadRecordQo qo) {
        PageUtils page = signCarLoadRecordService.queryLedgerDriver(qo);
        return R.ok().put("page", page);
    }

    /**
     * 按条件查询 各容器 处理的总收运量
     *
     * @param qo
     * @return
     */
    @PostMapping("/weightTotalGroupByContainer")
    public R weightTotalGroupByContainer(@RequestBody SignCarLoadRecordQo qo) {
        List<Map<String, Object>> mapList = signCarLoadRecordService.weightTotalGroupByContainer(qo);
        return R.ok().put("list", mapList);
    }

//    @PostMapping("/act")
//    public R act(@RequestBody SignCarLoadRecordQo qo){
//
//    }

    /**
     * 按条件查询 各卸水点 处理的总收运量
     *
     * @param qo
     * @return
     */
    @PostMapping("/weightTotalGroupBySink")
    public R weightTotalGroupBySink(@RequestBody SignCarLoadRecordQo qo) {
        List<Map<String, Object>> mapList = signCarLoadRecordService.weightTotalGroupBySink(qo);
        return R.ok().put("list", mapList);
    }

    /**
     * 总单查询
     *
     * @param params
     */
    @RequestMapping("/totalTable")
    public R totalTable(@RequestBody SignCarLoadRecordQo qo) {
        PageUtils page = signCarLoadRecordService.totalTable(qo);
        return R.ok().put("page", page);
    }

    /**
     * 按条件查询 各车辆 处理的总收运量
     *
     * @param qo
     * @return
     */
    @PostMapping("/weightTotalGroupByCar") //sign/signtask/weightTotalGroupByCar
    public R weightTotalGroupByCar(@RequestBody SignCarLoadRecordQo qo) {
        List<Map<String, Object>> mapList = signCarLoadRecordService.weightTotalGroupByCar(qo);
        return R.ok().put("list", mapList);
    }

    @PostMapping("/queryPageWeightTotalGroupByCar") //sign/signtask/weightTotalGroupByCar
    public R queryPageWeightTotalGroupByCar(@RequestBody SignCarLoadRecordQo qo) {
        PageUtils pageUtils = signCarLoadRecordService.queryPageWeightTotalGroupByCar(qo);
        return R.ok().put("page", pageUtils);
    }

    @PostMapping("/weightTotalGroupByTimeLength")
    public R weightTotalGroupByTimeLength(@RequestBody SignCarLoadRecordQo qo) {
        List<Map<String, Object>> mapList = signCarLoadRecordService.weightTotalGroupByTimeLength(qo);
        return R.ok().put("list", mapList);
    }

    @PostMapping("/weightGroupByCarAndTime")
    public R weightGroupByCarAndTime(@RequestBody SignCarLoadRecordQo qo) {
        List<Map<String, Object>> mapList = signCarLoadRecordService.weightGroupByCarAndTime(qo);
        return R.ok().put("list", mapList);
    }

    /**
     * 按条件查询 任务调度 处理的总收运量
     *
     * @param qo
     * @return
     */
    @PostMapping("/weightTotal")
    public R weightTotal(@RequestBody SignCarLoadRecordQo qo) {
        Double total = signCarLoadRecordService.weightTotal(qo);
        return R.ok().put("total", total);
    }


}
